POV-Ray : Newsgroups : povray.unofficial.patches : Poly is slower in megapov than in the official pov? : Re: Poly is slower in megapov than in the official pov? Server Time
2 Nov 2024 05:18:19 EDT (-0400)
  Re: Poly is slower in megapov than in the official pov?  
From: Nieminen Juha
Date: 15 Feb 2000 04:01:52
Message: <38a91600@news.povray.org>
I have a theory. It may be one cause of the slowdown, or it may not.
  Anyways, when I was looking at the pov source code in order to see how to
implement my fractal patch, I noticed that there are several places where
there are huge switch-case-constructs (for example when selecting the
pattern type or when parsing a keyword).
  Now megapov has LOTS of additional patterns, keywords, etc. Thus, those
switch-constructs are likewise a lot bigger.

  I don't know how the compiler handles those switch constructs, but if the
item to be selected is an integer type, I can't think of anything but a
bunch of if...else if...else if... structures. This, of course, is rather
slow when there is a considerable amount of cases.

  I'm not completely sure about this either, but I think that if the item
to be selected is an enum type, the compiler is able to optimize it so that
it can construct a look-up table with jumping addresses, and thus it can
generate a code that just indexes this table with the item and jumps to
that address. This is a lot faster, as you can imagine.

  I noticed that most things are #defined as integer constant in the povray
source code. For example:

#define BOZO_PATTERN            13
#define MARBLE_PATTERN          14
#define WOOD_PATTERN            15
#define SPOTTED_PATTERN         16

and so on.

  Perhaps it could be worth trying with an enum type instead? This way:

enum Pattern_type
{ BOZO_PATTERN,
  MARBLE_PATTERN,
  WOOD_PATTERN,
  SPOTTED_PATTERN,
  ...
}

  Of course every type that uses these values have to be changed from "int"
to "Pattern_type", but it _might_ generate a bit faster code, so it may
be worth the effort.
  Of course it could be tested with a test program before making the job.
  Hmm... I have to test it myself (if I find the time to do it...).

  This also makes it easier to add new types (the numeration changes
automatically as needed), so if nothing else, it's worth because of that.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.